﻿package mortal.game.view.godLuckGift
{
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.godLuckGift.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GodLuckGiftModule extends SpecialWindow
    {
        protected var _picBg:GImageBitmap;
        protected var _leftArr:CellsGridSprite;
        protected var _rightArr:CellsGridSprite;
        protected var _btn:GLoadingButton;
        protected var _btnLab:GBitmap;
        protected var _tBg:GBitmap;
        protected var _flyBtn:GLoadingButton;

        public function GodLuckGiftModule(param1:ILayer = null)
        {
            super(param1);
            this.setSize(646, 439);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.godLuckGift, this.onResLoad);
            return;
        }// end function

        private function onResLoad() : void
        {
            this._picBg = UIFactory.gImageBitmap(ImagesConst.GodLuckGiftModBg, 4, 34, this);
            this._leftArr = UIFactory.getUICompoment(CellsGridSprite);
            this._leftArr.colNum = 4;
            this._leftArr.vCellWid = 46;
            this._leftArr.hCellWid = 100;
            this._leftArr.genCellFun = this.getCell;
            this._leftArr.genCells(4);
            this._leftArr.x = 54;
            this._leftArr.y = 381;
            this.addChild(this._leftArr);
            this._rightArr = UIFactory.getUICompoment(CellsGridSprite);
            this._rightArr.colNum = 4;
            this._rightArr.vCellWid = 46;
            this._rightArr.hCellWid = 100;
            this._rightArr.genCellFun = this.getCell;
            this._rightArr.genCells(4);
            this._rightArr.x = 421;
            this._rightArr.y = 381;
            this.addChild(this._rightArr);
            this._btn = UIFactory.gLoadingButton(ImagesConst.GodLuckEnterBtn_upSkin, 276, 359, 113, 113, this);
            this._btn.label = "";
            this._btnLab = UIFactory.gBitmap(ImagesConst.GodLuckGiftBtnTip, 289, 406, this);
            this._tBg = UIFactory.gBitmap(ImagesConst.GodLuckGiftModTitle, 280, 6, this);
            this._flyBtn = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 291, 323, 80, 32, this);
            this._flyBtn.label = "" + Language.getString(71067);
            this.updateReward();
            this._btn.configEventListener(MouseEvent.CLICK, this.onEnterHd);
            this._flyBtn.configEventListener(MouseEvent.CLICK, this.onFlyHd);
            return;
        }// end function

        private function getCell(param1:Object = null) : BaseItem
        {
            var _loc_2:* = UIFactory.getUICompoment(BaseItem, 0, 0, this);
            _loc_2.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            return _loc_2;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._picBg = null;
            this._leftArr = null;
            this._rightArr = null;
            this._btn = null;
            this._btnLab = null;
            this._flyBtn = null;
            return;
        }// end function

        override protected function updateBtnSize() : void
        {
            if (_closeBtn)
            {
                _closeBtn.x = this.width - _closeBtn.width - 20;
                _closeBtn.y = 7;
            }
            return;
        }// end function

        private function updateReward() : void
        {
            var _loc_1:* = GodLuckGiftUtil.getRewardArr();
            this._leftArr.updateAllNotDispose(_loc_1[0], BaseItem, "itemData", false);
            this._rightArr.updateAllNotDispose(_loc_1[1], BaseItem, "itemData", false);
            return;
        }// end function

        private function onEnterHd(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GodLuckGiftGoAndCollect));
            this.hide();
            return;
        }// end function

        private function onFlyHd(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GodLuckGiftFlyAndCollect));
            return;
        }// end function

    }
}
